'''
Created on Sep 15, 2011

@author: QA
'''
import binascii
import hashlib
import os
import re
from DownSource import * 
from BeautifulSoup import BeautifulSoup

#print (hashlib.md5("Main.py").hexdigest().upper())

#smd5 = calc_hashes.getMD5("Main.py")
#bmd5 = binascii.unhexlify(smd5)

#print smd5

class App :
    counter = 0
    
    def foo(self, x):
        self.x = x
    
    @staticmethod
    def count():
        App.counter = App.counter + 1
    
    @staticmethod
    def printCounter():
        print App.counter   
        
#app = App()
#app.foo("abc")
#print app.x
#App.printCounter()
#App.count()
#App.printCounter()
#ds = DownSource("http://jingyan.baidu.com/goodExpList/0?pn=0")
#src = ds.get()
##print src
#
#soup = BeautifulSoup(''.join(src))
#soup = soup.findAll(attrs={'class' : 'f14 fbold'})
#for s in soup :
#    print s
#print len(soup)
#str = "http://jingyan.baidu.com/goodExpList/0?pn=0"
#
#p = re.compile('\s*<.*?>\s*')
#title = p.sub('', title)

def decodeHtmlentities(string):
    import re
    entity_re = re.compile("&(#?)(\d{1,5}|\w{1,8});")

    def substitute_entity(match):
        from htmlentitydefs import name2codepoint as n2cp
        ent = match.group(2)
        if match.group(1) == "#":
            return unichr(int(ent))
        else:
            cp = n2cp.get(ent)

            if cp:
                return unichr(cp)
            else:
                return match.group()

    return entity_re.subn(substitute_entity, string)[0]

print decodeHtmlentities("a&frac14;a&Oslash;")
print decodeHtmlentities("a&frac14;a&Oslash;")
